package web.ip;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @description
 * @className TestIp
 * @package web.ip
 * @author dongww@hsyuntai.com
 * @date 2020/3/11 16:18
 * @copyright 版权归 HSYUNTAI 所有
 */
public class TestIp {

    public static void main(String[] args) throws UnknownHostException {

        //获取本地主机
        InetAddress ip = InetAddress.getLocalHost();
        System.out.println(ip);
        //获得主机名
        System.out.println(ip.getHostName());
        //获得IP地址
        System.out.println(ip.getHostAddress());

        System.out.println(InetAddress.getByName("www.baidu.com"));
        System.out.println(InetAddress.getByName("www.baidu.com").getHostAddress());

    }
}